//
//  XMlParser.m
//  MyBook
//
//  Created by zhiyou on 16-3-19.
//  Copyright (c) 2016年 zhiyou. All rights reserved.
//

#import "XMlParser.h"
#import "Book.h"
@implementation XMlParser
-(id)initWithParser:(NSData *)data{
    self=[super init];
    if(self){
        _dataArray=[[NSMutableArray alloc]init];
        NSXMLParser*parser=[[NSXMLParser alloc]initWithData:data];
        parser.delegate=self;
        [parser parse];
    }
    return self;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    if([elementName isEqualToString:@"book"]){
        Book*book=[[Book alloc]initWithDic:attributeDict];
        [_dataArray addObject:book];
    }
}

@end
